package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.ServiceProviderAuditHistoryDTO;
import com.eastfair.venueservice.dto.ServiceProviderAuditHistoryPageQuery;
import com.eastfair.venueservice.dto.ServiceProviderAuditHistorySaveDTO;
import com.eastfair.venueservice.dto.ServiceProviderAuditHistoryUpdateDTO;
import com.eastfair.venueservice.entity.ServiceProviderAuditHistory;
import com.eastfair.venueservice.service.ServiceProviderAuditHistoryService;
import com.eastfair.venueservice.vo.ServiceProviderAuditHistoryVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 服务商审核历史表
 * </p>
 *
 * @author gj
 * @date 2022-07-13
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/serviceProviderAuditHistory")
@Api(value = "ServiceProviderAuditHistory", tags = "服务商审核历史表")
public class ServiceProviderAuditHistoryController extends SuperController<ServiceProviderAuditHistoryService, Long, ServiceProviderAuditHistory, ServiceProviderAuditHistoryPageQuery, ServiceProviderAuditHistorySaveDTO, ServiceProviderAuditHistoryUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ServiceProviderAuditHistoryService serviceProviderAuditHistoryService;

    @Override
    public void handlerResult(IPage<ServiceProviderAuditHistory> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<ServiceProviderAuditHistory> serviceProviderAuditHistoryList = list
                .stream()
                .map((map) -> ServiceProviderAuditHistory.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(serviceProviderAuditHistoryList));
    }


    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ServiceProviderAuditHistoryPageQuery> params) {
        ServiceProviderAuditHistoryPageQuery pageQuery = params.getModel();
        //分页处理
        if (ContextUtil.getProjectId() != null) {
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

    /**
     * 查询审核历史.
     *
     * @param pageParams the page params
     * @return the r
     */
    @PostMapping("/query/serviceProviderAuditHistory")
    public R<IPage<ServiceProviderAuditHistoryVO>> queryServiceProviderAuditHistory(@RequestBody PageParams<ServiceProviderAuditHistoryDTO> pageParams) {
        log.info("queryServiceProviderAuditHistory - 查询审核历史, pageParams={}", pageParams);
        return R.successDef(serviceProviderAuditHistoryService.listServiceProviderAuditHistoryVOs(pageParams));
    }

    /**
     * id查询审核历史详情.
     *
     * @param id the id
     * @return the by id
     */
    @GetMapping("/get/{id}")
    public R<ServiceProviderAuditHistoryVO> getById(@PathVariable("id") Long id) {
        log.info("getById - id查询审核历史详情, id={}", id);
        return R.successDef(serviceProviderAuditHistoryService.getVOById(id));
    }
}
